package applet;

import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AudioClip;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * 
 * @author gexj
 *
 */
public class AudioDemo extends Applet {
	private AudioClip clip;
	private AppletContext context;

	@Override
	public void init() {
		context = this.getAppletContext();
		String audioUrl = this.getParameter("audio");
		if (audioUrl == null) {
			audioUrl = "default.au";
		}
		try {
			URL url = new URL(this.getDocumentBase(), audioUrl);
			clip = context.getAudioClip(url);
		} catch (MalformedURLException e) {
			e.printStackTrace();
			context.showStatus("Could not load audio file!");
		}
	}

	@Override
	public void start() {
		if (clip != null) {
			clip.loop();
		}
	}

	@Override
	public void stop() {
		if (clip != null) {
			clip.stop();
		}
	}
}
